package com.example.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class VolatileTest {
    private static volatile AtomicInteger atomicInteger=new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {
//        new Thread(()->{
//            while (num==0){
//                System.out.println(num);
//            }
//        }).start();
//        TimeUnit.SECONDS.sleep(1);
//        num=1;
//        System.out.println("main");
        AtomicInteger atomicInteger = new AtomicInteger();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                for (int i1 = 0; i1 < 100; i1++) {
                    atomicInteger.getAndIncrement();
                }
            }).start();
        }
        TimeUnit.SECONDS.sleep(5);
        System.out.println(atomicInteger);
    }
}
